home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-13 | 2.4 KB | 100 lines | [TEXT/KAHL] |
-
-
- /* I was going to put "copyright (c)..." but that seemed
- a bit presumptuous given that regions were designed by
- Bill Atkinson. So,
-
- Written by Hugh Fisher, March 1993.
-
- This code is standard commercial quality: I think it
- works, and I'll fix any bugs you find, but it's not
- MY responsibility even if your computer melts.
- */
-
- void EachRegionRect (RgnHandle r, void (* proc)(Rect *));
-
- void EachRegionRect (RgnHandle r, void (* proc)(Rect *))
- {
- #define EndMark 32767
- #define MaxY 32767
- #define StackMax 1024
-
- typedef struct {
- short size;
- Rect bbox;
- short data[];
- } ** Internal;
-
- Internal region;
- short width, xAdjust, y, index, x1, x2, x;
- Rect box;
- short stackStorage[1024];
- short * buffer;
-
- region = (Internal)r;
-
- /* Check for plain rectangle */
- if ((**region).size == 10) {
- proc(&(**region).bbox);
- return;
- }
- /* Got to scale x coordinates into range 0..something */
- xAdjust = (**region).bbox.left;
- width = (**region).bbox.right - xAdjust;
- /* Most regions will be less than 1024 pixels wide */
- if (width < StackMax)
- buffer = stackStorage;
- else {
- buffer = (short *)NewPtr(width * 2);
- if (buffer == NULL)
- /* Truly humungous region or very low on memory.
- Quietly doing nothing seems to be the
- traditional Quickdraw response. */
- return;
- }
- /* Initialise scan line list to bottom edges */
- for (x = (**region).bbox.left; x < (**region).bbox.right; x++)
- buffer[x - xAdjust] = MaxY;
- index = 0;
- /* Loop until we hit an empty scan line */
- while ((**region).data[index] != EndMark) {
- y = (**region).data[index];
- index ++;
- /* Loop through horizontal runs on this line */
- while ((**region).data[index] != EndMark) {
- x1 = (**region).data[index];
- index ++;
- x2 = (**region).data[index];
- index ++;
- x = x1;
- while (x < x2) {
- if (buffer[x - xAdjust] < y) {
- /* We have a bottom edge - how long for? */
- box.left = x;
- box.top = buffer[x - xAdjust];
- while (x < x2 && buffer[x - xAdjust] == box.top) {
- buffer[x - xAdjust] = MaxY;
- x ++;
- }
- /* Pass to client proc */
- box.right = x;
- box.bottom = y;
- proc(&box);
- } else {
- /* This becomes a top edge */
- buffer[x - xAdjust] = y;
- x ++;
- }
- }
- }
- index ++;
- }
- /* Clean up after ourselves */
- if (width >= StackMax)
- DisposPtr((Ptr)buffer);
- #undef EndMark
- #undef MaxY
- #undef StackMax
- }
-
-